<?php
/*
 * litchicms
 * Copyright (C) 2010-5-11 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

!defined('BRK') && exit("!");

function template_parse_literal($string) {

    $all_literal=array();
/*
 * {literal}<?xml version="1.0" encoding="utf-8"?>{/literal}
 */
    preg_match_all("/\{literal\}(.*?)\{\/literal\}/is", $string  ,$all_literal);
    
    foreach ($all_literal[1] as &$v) {
        //$v=str_replace('$', "\\$", $v);
       // echo  $v;
        $v="<?php echo <<<END\n"
        .str_replace('$', '\\\\$', $v)."\n"
        ."END;\n"
        ."?>\n";
    }

    template_arr2patt($all_literal[0]);
    $string=preg_replace($all_literal[0], $all_literal[1], $string,1);

    if(preg_match("/\{literal\}|{\/literal\}/is", $string)){
        brk_log(0, "出现literal嵌套或者未成对") ;
    }

    return $string;
    
}
?>